/*
 * 浮点数精确比较、运算
 */

//浮点数加法运算  
function floatAdd(arg1,arg2,fixed){  
	var r1,r2,m;  
	try{r1=arg1.toString().split(".")[1].length;}catch(err){r1=0;}  
	try{r2=arg2.toString().split(".")[1].length;}catch(err){r2=0;}  
	m=Math.pow(10,Math.max(r1,r2));
	var result = (arg1*m+arg2*m)/m;
	return fixed ? new Number(result.toFixed(fixed)) : result;
}

//浮点数减法运算  
function floatSub(arg1,arg2,fixed){  
	var r1,r2,m,n;  
	try{r1=arg1.toString().split(".")[1].length;}catch(err){r1=0;}
	try{r2=arg2.toString().split(".")[1].length;}catch(err){r2=0;}
	m=Math.pow(10,Math.max(r1,r2));  
	n=(r1>=r2)?r1:r2;  
	var result = ((arg1*m-arg2*m)/m).toFixed(n);
	return fixed ? new Number(result.toFixed(fixed)) : result;
}

//浮点数乘法运算  
function floatMul(arg1,arg2,fixed){   
	var m=0,s1=arg1.toString(),s2=arg2.toString();   
	try{m+=s1.split(".")[1].length;}catch(err){}   
	try{m+=s2.split(".")[1].length;}catch(err){}   
	var result = Number(s1.replace(".",""))*Number(s2.replace(".",""))/Math.pow(10,m);
	return fixed ? new Number(result.toFixed(fixed)) : result;
}


//浮点数除法运算  
function floatDiv(arg1,arg2,fixed){   
	var t1=0,t2=0,r1,r2;   
	try{t1=arg1.toString().split(".")[1].length;}catch(err){}   
	try{t2=arg2.toString().split(".")[1].length;}catch(err){}   
	with(Math){   
		r1=Number(arg1.toString().replace(".",""));  
		r2=Number(arg2.toString().replace(".","")); 
		var result = (r1/r2)*pow(10,t2-t1);
		return fixed ? new Number(result.toFixed(fixed)) : result;
	}
}

//浮点数相等比较
function floatEq(arg1,arg2){
	return floatSub(arg1,arg2) == 0;
}

//浮点数大于比较
function floatMoreThan(arg1,arg2){
	return floatSub(arg1,arg2) > 0;
}

//浮点数小于比较
function floatLessThan(arg1,arg2){
	return floatSub(arg1,arg2) < 0;
}

//格式化秒
function formatSeconds(time){
	if (time == null) return "";
	time =  Math.floor(time);
	var mi = 60;
	var hh = mi * 60;
	var dd = hh * 24;

	var day = Math.floor(time / dd);
	var hour = Math.floor((time - day * dd) / hh);
	var minute = Math.floor((time - day * dd - hour * hh) / mi);
	var second = time - day * dd - hour * hh - minute * mi;
	return day + "天" + hour + "时" + minute + "分" + second + "秒";
}